package com.hotel.controller;

import com.hotel.pojo.Employee;
import com.hotel.service.EmployeeService;
import com.hotel.utils.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    //登录控制
    public ResultInfo login(Employee employee){
        ResultInfo resultInfo = employeeService.loginService(employee);
        if (resultInfo.getCode() == 200 || resultInfo.getCode() == -3){
            return new ResultInfo(200,"登录成功","redirect:/index.jsp");
        }
        return new ResultInfo(500, "登录失败", "error");
    }

    //员工查询
    @GetMapping("/employeeSelect")
    public ResultInfo employeeSelect(Integer selectId, int page, int size) {
        return employeeService.selectEmployee(selectId, page, size);
    }

    //员工删除
    @GetMapping("/employeeDelete")
    public ResultInfo employeeDelete(Integer employeeId) {
        return employeeService.deleteEmployee(employeeId);
    }

    //添加员工
    @PostMapping("/addEmployee")
    public ResultInfo addEmployee(Employee employee) {
        return employeeService.insertEmployee(employee);
    }

    //修改员工
    @PostMapping("/updateEmployee")
    public ResultInfo updateEmployee(Employee employee) {
        return employeeService.updateEmployee(employee);
    }
}








